#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Datetime: 2022/9/26 11:25
# @Author  : CHENWang
# @Site    :
# @File    : hourly_get_usdt_premium_data_check.py
# @Software: PyCharm

"""
脚本说明: usdt_premium_data_update 每小时运行
"""

import os
import time
import pandas as pd
from quant_researcher.quant.project_tool.localize import DATA_DIR
from quant_researcher.quant.project_tool.mail_tool import monitor_param, exceptionSimpleModel


def hourly_check():
    now = time.time()
    file_path = os.path.join(DATA_DIR, f'usdt_premium')
    file_name = os.path.join(file_path, f'okx_usdtcny_premium_ticker_log_prices.xlsx')
    okx_usdtcny_premium_ticker_log_prices = pd.read_excel(f'{file_name}')
    data_latest_date = okx_usdtcny_premium_ticker_log_prices['timestamp'].iloc[-1] / 1000
    if (now - data_latest_date)/60 > 40:  # 该函数会比数据爬取函数晚启动半小时，因此这里的意思是如果数据漏爬了
        exceptionSimple = exceptionSimpleModel()
        emailParam = monitor_param["email"]
        emailParam["subject"] = f"USDT-CNY折溢价数据爬取失败"
        message = 'USDT-CNY折溢价数据爬取失败'
        emailParam["message"] = [message]
        emailParam["receiver"] = ['156730794@qq.com']
        emailParam["CC"] = []
        exceptionSimple.except_main(1, emailParam)
        print('邮件发送成功')
    else:
        print('USDT-CNY折溢价数据爬取一切正常')


if __name__ == '__main__':
    # 获取usdt otc 兑 人民币价格
    # 数据需要网站爬取，部分数据（5m频）因为网站上不会保留那么久，因此需要每天爬取
    # 检测数据是否正常爬取，出现漏爬需要预警
    hourly_check()
